package com.superzqb.asus.superzqbFragment.superzqbShopMain.Adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.squareup.picasso.Picasso;
import com.superzqb.asus.superzqb.R;
import com.superzqb.asus.superzqbFragment.superzqbShopMain.Bean.GoodsTypeBean;
import com.superzqb.asus.superzqbUtil.MyItemClicklistener;
import com.superzqb.asus.superzqbUtil.Url;

import java.util.List;

/**
 * Created by asus on 2017/3/9.
 */

public class ShopAdapter extends RecyclerView.Adapter {
    private Context context;
    private List<GoodsTypeBean> items;
    private MyItemClicklistener mItemClickListener;
    public ShopAdapter (Context c,List<GoodsTypeBean> i){
        this.context=c;
        this.items=i;
    }
    public void setList(List<GoodsTypeBean> list) {
        this.items = list;
        notifyDataSetChanged();
    }
    public void setOnItemClickListener(MyItemClicklistener listener){
        this.mItemClickListener = listener;
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ShopViewHolder( LayoutInflater.from(context).inflate(R.layout.shop_main_item,parent,false),mItemClickListener);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ShopViewHolder v=(ShopViewHolder) holder;
        GoodsTypeBean obj=items.get(position);
        v.tv.setText(obj.getName());
        Picasso.with(context).load(new Url().getImg_url() +obj.getImg()).into(v.img);
    }

    @Override
    public int getItemCount() {
        if(items==null)
            return 0;
        else
            return items.size();
    }
}
